package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.AlertDataService;
import com.zzyl.vo.AlertDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-data")
@Api(tags = "管理端 - 报警数据相关接口")
public class AlertDataController {
    @Autowired
    private AlertDataService alertDataService;

    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页获取告警数据列表")
    public ResponseResult<PageResponse<AlertDataVo>> pageQuery(@ApiParam(value = "页码", required = true) @RequestParam("pageNum") Integer pageNum,
                                                               @ApiParam(value = "每页大小", required = true) @RequestParam("pageSize") Integer pageSize,
                                                               @ApiParam(value = "设备名称，精确查询") @RequestParam(value = "deviceName", required = false) String deviceName,
                                                               @ApiParam(value = "结束报警时间") @RequestParam(value = "endTime", required = false) Integer endTime,
                                                               @ApiParam(value = "报警数据id") @RequestParam(value = "id", required = false) Integer id,
                                                               @ApiParam(value = "开始报警时间") @RequestParam(value = "startTime", required = false) Integer startTime,
                                                               @ApiParam(value = "状态，0：待处理，1：已处理") @RequestParam(value = "status", required = false) Integer status){
        return ResponseResult.success(alertDataService.pageQuery(pageNum,pageSize,deviceName,endTime,id,startTime,status));
    }

    @PutMapping("/handleAlertData/{id}")
    @ApiOperation("处理设备报警数据")
    public ResponseResult handleAlertData(@PathVariable Long id){
        alertDataService.handleAlertData(id);
        return ResponseResult.success();
    }
}
